Our goal: Print out the headlines from the IRE home page.
requests
is a handy third-party library for making HTTP requests. It does the same thing your browser does when you type in a URL and hit enter -- sends a message to a server and requests a copy of the page -- but it allows us to do this programatically instead of pointing and clicking. For our purposes today, we're interested in the library's get()
method.
In [ ]:
import requests
from bs4 import BeautifulSoup
In [ ]:
# use the `get()` method to fetch a copy of the IRE home page
ire_page = requests.get('http://ire.org')
# feed the text of the web page to a BeautifulSoup object
soup = BeautifulSoup(ire_page.text, 'html.parser')
In [ ]:
# get a list of headlines we're interested in
heds = soup.find_all('h1', {'class': 'title1'})
In [ ]:
for hed in heds:
print(hed.a.string)
In [ ]: